home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / ctlib100.zip / INSTALL.LZH / DATA.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-12  |  19KB  |  487 lines

  1. {**************************************************************************}
  2. {*  BitSoft Development, L.L.C.                                           *}
  3. {*  Copyright (C) 1995, 1996 BitSoft Development, L.L.C.                  *}
  4. {*  All rights reserved.                                                  *}
  5. {**************************************************************************}
  6.  
  7. unit Data;
  8.  
  9. interface
  10.  
  11. uses Objects,
  12.      BsdTypes,
  13.      ctBiTree, ctCollec, Types, ctLists;
  14.  
  15. function CreateString (Key : String5; Index : Integer) : Pointer;
  16. { Function used to create strings that will be inserted in string
  17.   containers. }
  18.  
  19. type
  20.   PTestRec = ^TTestRec;
  21.   TTestRec = record
  22.     Key : String5;
  23.     Index : Integer;
  24.   end; { TTestRec }
  25.  
  26. function CreateTestRec (Key: String5; Index: Integer) : pointer;
  27. { Function used to create items of type TTestRec. }
  28.  
  29. procedure CreateNonDynamicTestRec (Key: String5; Index: Integer; var Data);
  30. { Procedure used to initialize a non-dynamically allocated TTestRec record. }
  31.  
  32. type
  33.   PTestObject = ^TTestObject;
  34.   TTestObject = object(TObject)
  35.       Text : PString;
  36.       Index : Integer;
  37.     constructor Init(Key : String5; AIndex : Integer);
  38.     constructor Load(var S: TStream);
  39.     procedure Store(var S: TStream);
  40.     destructor Done; virtual;
  41.   end; { TTestObject }
  42.  
  43. function CreateTestObject (Key: String5; Index: Integer) : pointer;
  44. { Function used to create items of type TTestObject. }
  45.  
  46. procedure CreateNonDynamicTestObject (Key: String5; Index: Integer; var Data);
  47. { Procedure used to initialize a non-dynamically allocated TTestObject. }
  48.  
  49. type
  50.   PTestStaticObject = ^TTestStaticObject;
  51.   TTestStaticObject = object(TObject)
  52.       Text : String5;
  53.       Index : Integer;
  54.     constructor Init(Key : String5; AIndex : Integer);
  55.     constructor Load(var S: TStream);
  56.     procedure Store(var S: TStream);
  57.   end; { TTestStaticObject }
  58.  
  59. function CreateStaticObject (Key: String5; Index: Integer) : pointer;
  60. { Function used to create items of type TTestStaticObject. }
  61.  
  62. procedure CreateNonDynamicTestStaticObject (Key: String5; Index: Integer;
  63.   var Data);
  64. { Procedure used to initialize a non-dynamically allocated
  65.   TTestStaticObject. }
  66.  
  67. type
  68.   PTestListNode = ^TTestListNode;
  69.   TTestListNode = object(TStringListNode)
  70.       Index : Integer;
  71.     constructor Init(Key : String5; AIndex : Integer);
  72.     constructor Load(var S: TStream);
  73.     procedure Store(var S: TStream);
  74.   end; { TTestListNode }
  75.  
  76. function CreateListNode (Key: String5; Index: Integer) : pointer;
  77. { Function used to create items of type TTestListNode. }
  78.  
  79. type
  80.   PTestDoubleNode = ^TTestDoubleNode;
  81.   TTestDoubleNode = object(TStringDoubleNode)
  82.       Index : Integer;
  83.     constructor Init(Key : String5; AIndex : Integer);
  84.     constructor Load(var S: TStream);
  85.     procedure Store(var S: TStream);
  86.   end; { TTestDoubleNode }
  87.  
  88. function CreateDoubleNode (Key: String5; Index: Integer) : pointer;
  89. { Function used to create items of type TTestDoubleNode. }
  90.  
  91. type
  92.   PTestBinaryNode = ^TTestBinaryNode;
  93.   TTestBinaryNode = object(TStringBinaryNode)
  94.       Index : Integer;
  95.     constructor Init(Key : String5; AIndex : Integer);
  96.     constructor Load(var S: TStream);
  97.     procedure Store(var S: TStream);
  98.   end; { TTestBinaryNode }
  99.  
  100. function CreateBinaryNode (Key: String5; Index: Integer) : pointer;
  101. { Function used to create items of type TTestBinaryNode. }
  102.  
  103. type
  104.   PTestAVLNode = ^TTestAVLNode;
  105.   TTestAVLNode = object(TStringAVLNode)
  106.       Index : Integer;
  107.     constructor Init(Key : String5; AIndex : Integer);
  108.     constructor Load(var S: TStream);
  109.     procedure Store(var S: TStream);
  110.   end; { TTestAVLNode }
  111.  
  112. function CreateAVLNode (Key: String5; Index: Integer) : pointer;
  113. { Function used to create items of type TTestAVLNode. }
  114.  
  115. const
  116.   RTestBinaryNode : TStreamRec = (
  117.     ObjType : idTestBinaryNode;
  118.     VmtLink : Ofs(TypeOf(TTestBinaryNode)^);
  119.     Load    : @TTestBinaryNode.Load;
  120.     Store   : @TTestBinaryNode.Store);
  121.  
  122.   RTestAVLNode : TStreamRec = (
  123.     ObjType : idTestAVLNode;
  124.     VmtLink : Ofs(TypeOf(TTestAVLNode)^);
  125.     Load    : @TTestAVLNode.Load;
  126.     Store   : @TTestAVLNode.Store);
  127.  
  128.   RTestObject : TStreamRec = (
  129.     ObjType : idTestObject;
  130.     VmtLink : Ofs(TypeOf(TTestObject)^);
  131.     Load    : @TTestObject.Load;
  132.     Store   : @TTestObject.Store);
  133.  
  134.   RTestListNode : TStreamRec = (
  135.     ObjType : idTestListNode;
  136.     VmtLink : Ofs(TypeOf(TTestListNode)^);
  137.     Load    : @TTestListNode.Load;
  138.     Store   : @TTestListNode.Store);
  139.  
  140.   RTestDoubleNode : TStreamRec = (
  141.     ObjType : idTestDoubleNode;
  142.     VmtLink : Ofs(TypeOf(TTestDoubleNode)^);
  143.     Load    : @TTestDoubleNode.Load;
  144.     Store   : @TTestDoubleNode.Store);
  145.  
  146.   RTestStaticObject : TStreamRec = (
  147.     ObjType : idTestStaticObject;
  148.     VmtLink : Ofs(TypeOf(TTestStaticObject)^);
  149.     Load    : @TTestStaticObject.Load;
  150.     Store   : @TTestStaticObject.Store);
  151.  
  152. implementation
  153.  
  154. {****************************************************************************}
  155. { CreateAVLNode                                                              }
  156. {****************************************************************************}
  157. function CreateAVLNode (Key : String5; Index: Integer) : pointer;
  158. var
  159.   Item : PTestAVLNode;
  160. begin
  161.   Item := New(PTestAVLNode, Init(Key, Index));
  162.   CreateAVLNode := Item;
  163. end;
  164.  
  165. {****************************************************************************}
  166. { CreateBinaryNode                                                           }
  167. {****************************************************************************}
  168. function CreateBinaryNode (Key : String5; Index: Integer) : pointer;
  169. var
  170.   Item : PTestBinaryNode;
  171. begin
  172.   Item := New(PTestBinaryNode, Init(Key, Index));
  173.   CreateBinaryNode := Item;
  174. end;
  175.  
  176. {****************************************************************************}
  177. { CreateDoubleNode                                                           }
  178. {****************************************************************************}
  179. function CreateDoubleNode (Key : String5; Index : Integer) : Pointer;
  180. var
  181.   Item : PTestDoubleNode;
  182. begin
  183.   Item := New(PTestDoubleNode, Init(Key, Index));
  184.   CreateDoubleNode := Item;
  185. end;
  186.  
  187. {****************************************************************************}
  188. { CreateListNode                                                             }
  189. {****************************************************************************}
  190. function CreateListNode (Key : String5; Index : Integer) : Pointer;
  191. var
  192.   Item : PTestListNode;
  193. begin
  194.   Item := New(PTestListNode, Init(Key, Index));
  195.   CreateListNode := Item;
  196. end;
  197.  
  198. {****************************************************************************}
  199. { CreateNonDynamicTestObject                                                 }
  200. {****************************************************************************}
  201. procedure CreateNonDynamicTestObject (Key: String5; Index: Integer; var Data);
  202. begin
  203.   TTestObject(Data).Init(Key, Index);
  204. end;
  205.  
  206. {****************************************************************************}
  207. { CreateNonDynamicTestRec                                                    }
  208. {****************************************************************************}
  209. procedure CreateNonDynamicTestRec (Key: String5; Index: Integer; var Data);
  210. begin
  211.   TTestRec(Data).Key := Key;
  212.   TTestRec(Data).Index := Index;
  213. end;
  214.  
  215. {****************************************************************************}
  216. { CreateNonDynamicTestStaticObject                                           }
  217. {****************************************************************************}
  218. procedure CreateNonDynamicTestStaticObject (Key: String5; Index: Integer;
  219.   var Data);
  220. begin
  221.   TTestStaticObject(Data).Init(Key, Index);
  222. end;
  223.  
  224. {****************************************************************************}
  225. { CreateStaticObject                                                         }
  226. {****************************************************************************}
  227. function CreateStaticObject (Key : String5; Index : Integer) : Pointer;
  228. var
  229.   Item : PTestStaticObject;
  230. begin
  231.   Item := New(PTestStaticObject, Init(Key, Index));
  232.   CreateStaticObject := Item;
  233. end;
  234.  
  235. {****************************************************************************}
  236. { CreateString                                                               }
  237. {****************************************************************************}
  238. function CreateString (Key : String5; Index : Integer) : Pointer;
  239. begin
  240.   CreateString := NewStr(Key);
  241. end;
  242.  
  243. {****************************************************************************}
  244. { CreateTestObject                                                           }
  245. {****************************************************************************}
  246. function CreateTestObject (Key : String5; Index : Integer) : Pointer;
  247. var
  248.   Item : PTestObject;
  249. begin
  250.   Item := New(PTestObject, Init(Key, Index));
  251.   Item^.Index := Index;
  252.   CreateTestObject := Item;
  253. end;
  254.  
  255. {****************************************************************************}
  256. { CreateTestRec                                                              }
  257. {****************************************************************************}
  258. function CreateTestRec (Key : String5; Index : Integer) : Pointer;
  259. var
  260.   Item : PTestRec;
  261. begin
  262.   New(Item);
  263.   Item^.Key := Key;
  264.   Item^.Index := Index;
  265.   CreateTestRec := Item;
  266. end;
  267.  
  268. {****************************************************************************}
  269. { TTestAVLNode object                                                        }
  270. {****************************************************************************}
  271. {****************************************************************************}
  272. { TTestAVLNode.Init                                                          }
  273. {****************************************************************************}
  274. constructor TTestAVLNode.Init(Key : String5; AIndex : Integer);
  275. begin
  276.   TStringAVLNode.Init(Key);
  277.   Index := AIndex;
  278. end;
  279.  
  280. {****************************************************************************}
  281. { TTestAVLNode.Load                                                          }
  282. {****************************************************************************}
  283. constructor TTestAVLNode.Load(var S: TStream);
  284. begin
  285.   if not TStringAVLNode.Load(S)
  286.     then Fail;
  287.   S.Read(Index, SizeOf(Index));
  288.   if S.Status <> stOk
  289.     then begin
  290.            Done;
  291.            Fail;
  292.          end; { if }
  293. end;
  294.  
  295. {****************************************************************************}
  296. { TTestAVLNode.Store                                                         }
  297. {****************************************************************************}
  298. procedure TTestAVLNode.Store(var S: TStream);
  299. begin
  300.   TStringAVLNode.Store(S);
  301.   S.Write(Index, SizeOf(Index));
  302. end;
  303.  
  304. {****************************************************************************}
  305. { TTestBinaryNode object                                                     }
  306. {****************************************************************************}
  307. {****************************************************************************}
  308. { TTestBinaryNode.Init                                                       }
  309. {****************************************************************************}
  310. constructor TTestBinaryNode.Init(Key : String5; AIndex : Integer);
  311. begin
  312.   TStringBinaryNode.Init(Key);
  313.   Index := AIndex;
  314. end;
  315.  
  316. {****************************************************************************}
  317. { TTestBinaryNode.Load                                                       }
  318. {****************************************************************************}
  319. constructor TTestBinaryNode.Load(var S: TStream);
  320. begin
  321.   if not TStringBinaryNode.Load(S)
  322.     then Fail;
  323.   S.Read(Index, SizeOf(Index));
  324.   if S.Status <> stOk
  325.     then begin
  326.            Done;
  327.            Fail;
  328.          end; { if }
  329. end;
  330.  
  331. {****************************************************************************}
  332. { TTestBinaryNode.Store                                                      }
  333. {****************************************************************************}
  334. procedure TTestBinaryNode.Store(var S: TStream);
  335. begin
  336.   TStringBinaryNode.Store(S);
  337.   S.Write(Index, SizeOf(Index));
  338. end;
  339.  
  340. {****************************************************************************}
  341. { TTestDoubleNode object                                                     }
  342. {****************************************************************************}
  343. {****************************************************************************}
  344. { TTestDoubleNode.Init                                                       }
  345. {****************************************************************************}
  346. constructor TTestDoubleNode.Init(Key : String5; AIndex : Integer);
  347. begin
  348.   if not TStringDoubleNode.Init(Key)
  349.     then Fail;
  350.   Index := AIndex;
  351. end;
  352.  
  353. {****************************************************************************}
  354. { TTestDoubleNode.Load                                                       }
  355. {****************************************************************************}
  356. constructor TTestDoubleNode.Load(var S: TStream);
  357. begin
  358.   if not TStringDoubleNode.Load(S)
  359.     then Fail;
  360.   S.Read(Index, SizeOf(Index));
  361. end;
  362.  
  363. {****************************************************************************}
  364. { TTestDoubleNode.Store                                                      }
  365. {****************************************************************************}
  366. procedure TTestDoubleNode.Store(var S: TStream);
  367. begin
  368.   TStringDoubleNode.Store(S);
  369.   S.Write(Index, SizeOf(Index));
  370. end;
  371.  
  372. {****************************************************************************}
  373. { TTestListNode object                                                       }
  374. {****************************************************************************}
  375. {****************************************************************************}
  376. { TTestListNode(Key                                                          }
  377. {****************************************************************************}
  378. constructor TTestListNode.Init(Key : String5; AIndex : Integer);
  379. begin
  380.   if not TStringListNode.Init(Key)
  381.     then Fail;
  382.   Index := AIndex;
  383. end;
  384.  
  385. {****************************************************************************}
  386. { TTestListNode.Load                                                         }
  387. {****************************************************************************}
  388. constructor TTestListNode.Load(var S: TStream);
  389. begin
  390.   if not TStringListNode.Load(S)
  391.     then Fail;
  392.   S.Read(Index, SizeOf(Index));
  393. end;
  394.  
  395. {****************************************************************************}
  396. { TTestListNode.Store                                                        }
  397. {****************************************************************************}
  398. procedure TTestListNode.Store(var S: TStream);
  399. begin
  400.   TStringListNode.Store(S);
  401.   S.Write(Index, SizeOf(Index));
  402. end;
  403.  
  404. {****************************************************************************}
  405. { TTestObject object                                                         }
  406. {****************************************************************************}
  407. {****************************************************************************}
  408. { TTestObject.Init                                                           }
  409. {****************************************************************************}
  410. constructor TTestObject.Init(Key : String5; AIndex : Integer);
  411. begin
  412.   if not TObject.Init
  413.     then Fail;
  414.   Text := NewStr(Key);
  415.   Index := AIndex;
  416. end;
  417.  
  418. {****************************************************************************}
  419. { TTestObject.Load                                                           }
  420. {****************************************************************************}
  421. constructor TTestObject.Load(var S: TStream);
  422. begin
  423.   if not TObject.Init
  424.     then Fail;
  425.   Text := S.ReadStr;
  426.   S.Read(Index, SizeOf(Index));
  427. end;
  428.  
  429. {****************************************************************************}
  430. { TTestObject.Done                                                           }
  431. {****************************************************************************}
  432. destructor TTestObject.Done;
  433. begin
  434.   DisposeStr(Text);
  435.   TObject.Done;
  436. end;
  437.  
  438. {****************************************************************************}
  439. { TTestObject.Store                                                          }
  440. {****************************************************************************}
  441. procedure TTestObject.Store(var S: TStream);
  442. begin
  443.   S.WriteStr(Text);
  444.   S.Write(Index, SizeOf(Index));
  445. end;
  446.  
  447. {****************************************************************************}
  448. { TTestStaticObject object                                                   }
  449. {****************************************************************************}
  450. {****************************************************************************}
  451. { TTestStaticObject.Init                                                     }
  452. {****************************************************************************}
  453. constructor TTestStaticObject.Init(Key : String5; AIndex : Integer);
  454. begin
  455.   if not TObject.Init
  456.     then Fail;
  457.   FillChar(Text, SizeOf(Text), #0);
  458.   Text := Key;
  459.   Index := AIndex;
  460. end;
  461.  
  462. {****************************************************************************}
  463. { TTestStaticObject.Load                                                     }
  464. {****************************************************************************}
  465. constructor TTestStaticObject.Load(var S: TStream);
  466. begin
  467.   if not TObject.Init
  468.     then Fail;
  469.   S.Read(Text, SizeOf(Text));
  470.   S.Read(Index, SizeOf(Index));
  471.   if S.Status <> stOk
  472.     then begin
  473.            TObject.Done;
  474.            Fail;
  475.          end; { if }
  476. end;
  477.  
  478. {****************************************************************************}
  479. { TTestStaticObject.Store                                                    }
  480. {****************************************************************************}
  481. procedure TTestStaticObject.Store(var S: TStream);
  482. begin
  483.   S.Write(Text, SizeOf(Text));
  484.   S.Write(Index, SizeOf(Index));
  485. end;
  486.  
  487. end.